<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.io.Console"%>
<%@page import="java.util.logging.ConsoleHandler"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Calibri, Cambria}
.style3 {font-family: Verdana, Calibri, Cambria; font-size: small; }
.style4 {
	font-family: Verdana, Calibri, Cambria;
	font-weight: bold;
	font-style: italic;
	color: #FFFFFF;
}
.style5 {font-size: small}
-->
</style>
</head>

<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"><img src="images/title.png" width="700" height="100"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        <td colspan="3" align="center"><div align="left">
          <p class="style3">
          
          <%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			String user = session.getAttribute("user").toString();
			String type = session.getAttribute("type").toString();
			String matr = session.getAttribute("matricola").toString();
			String nome = session.getAttribute("nome").toString();
			String cogn = session.getAttribute("cognome").toString();
			
			out.println("Benvenuto " + user);
			}
		%>
		
<%! String oracleUser = "azienda";
	String oraclePwd  = "azienda";
	Connection conn;
	String driver;
	String oracle;
	String user;
	String codice,denominazione,posizione,note; 
	Statement st;
	ResultSet rs;
%>
<%
	user = session.getAttribute("user").toString().toLowerCase();
	driver = "oracle.jdbc.driver.OracleDriver";
	oracle = "jdbc:oracle:thin:@localhost:1521:xe"; 
	
	try {
		Class.forName(driver);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	
	try {
		conn = DriverManager.getConnection(oracle, oracleUser, oraclePwd);
		st = conn.createStatement();
	} catch (SQLException e) {
		e.printStackTrace();
	}
%>
		  </p>
        </div></td>
        </tr>
      <tr>
        <td width="8%" class="style1"><p align="left">&nbsp;</p></td>
        <td width="33%" class="style1"><strong>Cerca una stanza </strong></td>
        <td width="59%" class="style1">
		<form action="gestione_stanza.jsp" method="post">
			<input type="text" size="60%" name="field" value="" />
			<br/>
			<input type="radio" name="optselect" value="0" checked="true"/>
			<span class="style5">coidce</span>
			<input type="radio" name="optselect" value="1" />
			<span class="style5">denominazione</span>
			<input type="submit" name="btnget" value="OK" />
			<br/>
		</form>		</td>
      </tr>
      <tr>
        <td colspan="3" class="style1"><div align="center"></div></td>
        </tr>
      <tr>
        <td colspan="3" class="style1"><table width="100%" cellpadding="2" cellspacing="0" bordercolor="#000000" style="border:1px solid;">
          <tr>
            <td width="8%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >PROG.</div></td>
            <td width="17%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >CODICE</div></td>
            <td width="21%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >DENOMINAZIONE</div></td>
            <td width="26%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >POSIZIONE</div></td>
            <td width="28%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >NOTE</div></td>
          </tr>

<%
				
	int optselect=0; 
	String field=""; 
	String qry="";
	
	if(request.getParameter("optselect")!=null) optselect=Integer.parseInt(request.getParameter("optselect").toString().toLowerCase());
	if(request.getParameter("field")!=null)     field=request.getParameter("field").toString().toLowerCase();
	
	if(field==""&&optselect==0) field = "0";
	if(field.length()<16&&optselect==1) field = "";
	
	switch(optselect)
	{
	case 0: qry = "select * from stanza where codice = "+field+" order by codice";         					 break;//cerco per matricola
	case 1: qry = "select * from stanza where lower(denominazione) like '"+field+"%' order by denominazione"; break;//cerco per codice fiscale
	default : qry = "select * from personale where 1=0";												  break;//non cerco niente
	}
		rs = st.executeQuery(qry);
		int i=0;
		
		if(rs.isBeforeFirst()&&rs.isAfterLast())
		{
			//Avvisare che non ci sono record!!!!
		}
		else
		{
			while (rs.next())
			{
				codice = rs.getString("codice");
				denominazione = rs.getString("denominazione");
				posizione=rs.getString("posizione");
				note=rs.getString("note");
				
				String color;
	            		String bordercell;
	            		
	            		i++;
	            		
	            		if (i%2==0)
	            		{
	            			color ="\"#E0E0E0\"";
	            			bordercell="style=\"border:1px solid;\";";
	            		}
	            		else
	            		{
	            			color = "\"#EFFFEF\"";
	            			bordercell="style=\"border:1px solid;\";";
	            		}
	            		
	            		out.println("<tr>");
	            		out.println("<td align=\"right\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + i + "</td>"); //prog.
	            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ "><a href=\"modifica_stanza.jsp?codice="+codice+"&modify=0\">" + codice + "</a></td>");//
	            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + denominazione + "</td>");
	            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + posizione + "</td>");
	            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + note + "</td>");
	            		out.println("</tr>");
		}
	}
	
	//rs.close();
	//st.close();
	//conn.close();
	
          %>
        </table></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle"><input type="button" value="INDIETRO" onClick="location.href='gestione_stanze.jsp'" /></td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#000099"><div align="right" class="style4">GESTIONE STANZA </div></td>
  </tr>
</table>
</body>
</html>
